package com.File;

import org.junit.jupiter.api.Test;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class reader01 {
    public static void main(String[] args) {
        String filePath = "d:\\news.txt";
        FileReader fileReader = null;
        int data = 0;
        try {
            fileReader= new FileReader(filePath);
            while ((data = fileReader.read())!=-1){
                System.out.print((char)data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    @Test
    public void reader(){
        String filePath = "d:\\news.txt";
        FileReader fileReader = null;
        int readLen = 0;
        char[]buf = new char[8];
        try {
            fileReader= new FileReader(filePath);
            while ((readLen = fileReader.read(buf))!=-1){
                System.out.print(new String(buf,0,readLen));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
